package com.ruicar.afs.cloud.afscase.step.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.afscase.step.entity.CaseStepParam;
import com.ruicar.afs.cloud.afscase.step.mapper.CaseStepParamMapper;
import com.ruicar.afs.cloud.afscase.step.service.CaseStepParamService;
import com.ruicar.afs.cloud.common.modules.afscorebusiness.enums.StepSceneEnum;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description
 * @Author Peng Jinbo
 * @Date 2020/08/28 11:54
 */
@Service
@AllArgsConstructor
public class CaseStepParamServiceImpl extends ServiceImpl<CaseStepParamMapper, CaseStepParam> implements CaseStepParamService {
    @Override
    public CaseStepParam getLast(String applyNo, StepSceneEnum scene) {
        return list(
                Wrappers.<CaseStepParam>lambdaQuery()
                    .eq(CaseStepParam::getApplyNo,applyNo)
                    .eq(Objects.nonNull(scene),CaseStepParam::getScene,scene)
                    .orderByDesc(CaseStepParam::getCreateTime)
        ).stream().findFirst().orElse(new CaseStepParam());
    }

    @Override
    public boolean clear(String applyNo, StepSceneEnum scene) {
        return remove(
                Wrappers.<CaseStepParam>lambdaQuery()
                    .eq(CaseStepParam::getApplyNo,applyNo)
                    .eq(CaseStepParam::getScene,scene)
        );
    }
}
